package com.tobias.gaokao.dao;

import com.tobias.gaokao.model.Student;
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface StudentRepository extends JpaRepository<Student, Integer> {
    Student findByName(String name);

    List<Student> findAllByUniqueNumber(String uniqueNumber);

    Student findBySocialId(String socialId);

//    public UserInfo findByUsernameIgnoreCase(String username);
//
//	@Transactional
//	@Modifying(clearAutomatically = true)
//	@Query("UPDATE UserInfo SET attempts = :attempts WHERE id = :id")
//	public void updateUserAttempt(@Param("id") Integer id, @Param("attempts") Integer attempts);
//
//	@Query("SELECT userRoleMapper FROM UserRoleMapper userRoleMapper where userRoleMapper.roleId = :roleId")
//	public List<UserRoleMapper> fetchUsersByRole(@Param("roleId") Integer roleId);
//
//	@Query("SELECT userInfo FROM UserInfo userInfo where userInfo.id IN :userIds and userInfo.active = 1 ORDER BY userInfo.created DESC")
//	public List<UserInfo> fetchEnabledUsersByIds(@Param("userIds") List<Integer> userIds);
//
//	@Query("SELECT DISTINCT userInfo FROM UserInfo userInfo INNER JOIN userInfo.roles role where role.id IN :roles")
//    public List<UserInfo> fetchUsersByIds(@Param("roles") List<Integer> roles, Sort sort);
//
//	@Query("SELECT userInfo FROM UserInfo userInfo where userInfo.email = :email")
//	public UserInfo getUserByEmail(@Param("email") String email);
//
//	@Transactional
//	@Modifying(clearAutomatically = true)
//	@Query("UPDATE UserInfo SET active = :active WHERE username = :username")
//	public Integer enableDisableUser(@Param("username")String username, @Param("active")Integer active);
//
//    @Transactional
//    @Modifying(clearAutomatically = true)
//    @Query("UPDATE UserInfo SET active = :status, attempts = 0, updatedBy = :updatedBy, updated = :updatedTime WHERE id = :userId")
//    public Integer flipUserStatus(@Param("userId") Integer userId, @Param("status") Integer status, @Param("updatedBy") Integer updatedBy, @Param("updatedTime") LocalDateTime updatedTime);
//
//    @Query("SELECT new com.s4m.util.model.UserResponse(userInfo.id, userInfo.username, userInfo.firstName, userInfo.lastName, userInfo.email) FROM UserInfo userInfo, UserRoleMapper urm WHERE userInfo.id = urm.userId AND urm.roleId = :role")
//	public UserResponse fetchUserByRole(@Param("role") Integer role);
//
//    @Query("SELECT DISTINCT new com.s4m.util.model.UserResponse(userInfo.id, userInfo.username, userInfo.firstName, userInfo.lastName, userInfo.email) FROM UserInfo userInfo INNER JOIN userInfo.roles role where role.id IN :role")
//    public List<UserResponse> fetchUserByRoles(@Param("role") List<Integer> role);
//
//    @Transactional
//	@Modifying(clearAutomatically = true)
//	@Query("UPDATE UserInfo SET password = :password, initialLogin=:initialLogin WHERE id = :userId")
//	public void updatePassword(@Param("password")String password, @Param("initialLogin")Integer initialLogin, @Param("userId")Integer userId);
//
//    @Query("SELECT userInfo FROM UserInfo userInfo where userInfo.id IN :userIds ORDER BY userInfo.created DESC")
//	public List<UserInfo> fetchUsersByIds(@Param("userIds") List<Integer> userIds);
//
//    @Transactional
//    @Modifying(clearAutomatically = true)
//    @Query("DELETE FROM UserInfo WHERE id IN :userIds")
//    public Integer deleteUsersByIds(@Param("userIds") List<Integer> userIds);
//
//    @Query("Select Count(*) from UserInfo userInfo where  userInfo.id in ( Select userRoleMapper.userId from  UserRoleMapper userRoleMapper where userRoleMapper.roleId in (Select role.id from Role role where role.organization.orgKey = :orgKey) )")
//    public Long countUsersByOrgKey(@Param("orgKey") String orgKey);
//
//    @Query("Select email from UserInfo where id in (select userId from UserRoleMapper where roleId in (select id from Role where roleName = 'TENANT_ADMIN'))")
//    public List<String> fetchTenantEmails();
}
